package com.diet.web.controller.diet;

import com.diet.common.core.controller.BaseController;
import com.diet.common.core.domain.AjaxResult;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 营养规划Controller
 */
@RestController
@RequestMapping("/diet/nutrition")
public class NutritionController extends BaseController
{
    /**
     * 获取用户营养需求
     */
    @GetMapping("/needs")
    public AjaxResult getNutritionNeeds()
    {
        Map<String, Object> data = new HashMap<>();
        data.put("energy", 720.57);
        data.put("protein", 27.0);
        data.put("fat", 20.0);
        data.put("carbohydrate", 108.1);
        data.put("mealType", "lunch");
        return AjaxResult.success(data);
    }

    /**
     * 生成营养规划方案
     */
    @PostMapping("/plan")
    public AjaxResult generateNutritionPlan(@RequestBody Map<String, Object> params)
    {
        // 模拟营养规划算法
        Map<String, Object> plan = new HashMap<>();
        plan.put("planId", 1);
        plan.put("deviationRate", 5.2);
        
        // 模拟食材营养成分
        Map<String, Object> ingredient1 = new HashMap<>();
        ingredient1.put("name", "猪肉");
        ingredient1.put("amount", 80);
        ingredient1.put("energy", 316);
        ingredient1.put("protein", 10.6);
        ingredient1.put("fat", 29.6);
        ingredient1.put("carbohydrate", 0);
        
        Map<String, Object> ingredient2 = new HashMap<>();
        ingredient2.put("name", "大米");
        ingredient2.put("amount", 100);
        ingredient2.put("energy", 346);
        ingredient2.put("protein", 7.4);
        ingredient2.put("fat", 0.8);
        ingredient2.put("carbohydrate", 77.9);
        
        plan.put("ingredients", new Object[]{ingredient1, ingredient2});
        
        return AjaxResult.success(new Object[]{plan});
    }
}